let db = require('../db/index')

exports.all = (req, res) => {        //获取memberlist表全部数据
    var sql = 'select * from memberlist_yang'
    db.query(sql, (err, data) => {
        if(err) {
            return res.send('错误：' + err.message)
        }
        res.send(data)
    })
}
exports.get = (req, res) => {        //通过number查询数据
    var sql = 'select * from memberlist_yang where  number =? or class=? or name=?'    //？用于占位
    db.query(sql, [req.query.number,req.query.class,req.query.name], (err, data) => {
        if(err) {
            return res.send('错误：' + err.message)
        }
        res.send(data)
    })
}


exports.del = (req, res) => {        //通过id删除数据
    var sql = 'delete from memberlist_yang where id = ?'
    db.query(sql, [req.query.id], (err, data) => { 
        if(err) {
            return res.send('错误：' + err.message)
        }
        res.send(data)
    })
}

exports.add = (req, res) => {        //向memberlist表添加数据
    var sql = 'insert into memberlist_yang (id,name,class,password,number,club) values (?,?,?,?,?,?)'
    db.query(sql, [req.query.id, req.query.name, req.query.class, req.query.password, req.query.number, req.query.club], (err, data) => {
        if(err) {
            return res.send('错误：' + err.message)
        }
        res.send(data)
    })
}

exports.update = (req, res) => {        //通过id更新数据
    var sql = 'update memberlist_yang set name = ?, class = ?, password = ?, number = ?, club = ? where id = ?'
    db.query(sql, [req.query.name, req.query.class,req.query.password, req.query.number, req.query.club, req.query.id,], (err, data) => {
        if(err) {
            return res.send('错误：' + err.message)
        }
        res.send(data)
    })
}

